import { Events } from '@tarojs/taro';
import { useEffect } from 'react';

const emit = new Events();

export const EventTypeEum = {
  // 家庭列表
  // FAMILYLIST: 'FAMILYLIST',
};

export const useRegisterEvent = (
  name: keyof typeof EventTypeEum | undefined,
  fun: (...args: any[]) => void,
  deps: any[] = []
) => {
  useEffect(() => {
    name && emit.on(name, fun);
    return () => {
      name && emit.off(name);
    };
  }, deps);
};

export default (name: keyof typeof EventTypeEum, ...args: any[]) => {
  emit.trigger(name, ...args);
};
